package day1107;

import java.time.*;

import static common.PrintUtil.printLine;

/**
 * @author Mr.ma
 * @since 2022/11/7 18:41
 * 日期时间对象计算时间间隔需要依靠Period和Duration两个类的类对象，
 * 两个类的构造方法都进行了私有化，需要调用类中的公开静态方法创建对象
 * Period中常用方法：
 *      getDays(),getMonths(),getYears()
 **/
public class DateComparatorTest {
    public static void main(String[] args) {
        printLine("获取从1999-12-20到现在的时间间隔");
        Period dateBetween = Period.between(LocalDate.of(1999, 12, 20), LocalDate.now());
        int years = dateBetween.getYears();
        int months = dateBetween.getMonths();
        int days = dateBetween.getDays();
        System.out.println("二者相差" + years + "年" + months + "月" + days + "天");
        printLine("获取从07:00:00开始到现在过去了多长时间");
        Duration timeBetween = Duration.between(LocalTime.of(7, 0, 0), LocalTime.now());
        System.out.println("过去了" + timeBetween.toHours() + "小时");
        System.out.println("也就是" + timeBetween.toMinutes() + "分钟");
        System.out.println("相当于" + timeBetween.getSeconds() + "秒");
    }
}
